/*************************************************
Author: will
Date: 11/8/2012
Description:
Notes: 
*************************************************/

#ifndef __CUserCard_h__
#define __CUserCard_h__

#include "CTHashObjectMgr.h"
#include "commclass.h"
#include "../storage/CUserStorage.h"
#include "CCardConfig.h"

class CUserSingleCard
{
public:
    CUserSingleCard()
    {

    }

    virtual ~CUserSingleCard()
    {

    }

public:
    CSingleCardData  _stCardData;
};

class CCardMgr;
class CUserCard
{
public:
    friend class CCardMgr;
    friend class CCmdCardRole;
    typedef CTLib::CTHashObjectMgr<unsigned int, CUserSingleCard> T_USER_CARD_HASH;

    CUserCard()
        :_iNowCardID(0)
    {

    }

    virtual ~CUserCard()
    {

    }

    static size_t CountSize()
    {
        return CUserStorage::CountSize() 
                    + T_USER_CARD_HASH::CountSize(MAX_CARD_COUNT);
    }
    
    int Init(const char* sBuff)
    {
        int iRet = 0;
        int iOffset = 0;

        iRet = _stCardStorage.Init(sBuff + iOffset);
        CHECK_RETURN(iRet);
        iOffset += CUserStorage::CountSize();

        iRet = _stCardHash.Init(sBuff + iOffset, MAX_CARD_COUNT);
        CHECK_RETURN(iRet);
        iOffset += T_USER_CARD_HASH::CountSize(MAX_CARD_COUNT);

        return 0;
    }

    void Clear()
    {
        _uiGID = 0;
        _iNowCardID = 0;
    
        _stCardStorage.Clear();
        for (int iIndex = _stCardHash.GetHeadIndex();
            iIndex >= 0; iIndex = _stCardHash.GetHeadIndex())
        {
            _stCardHash.HashFreeByIndex(iIndex);
        }

        _stCardStorage.SetMaxBagGridCount(MAX_CARD_BUG_GRID_COUNT);
        _stCardStorage.SetMaxWareHouseGridCount(0);
    }

    int GetBagEmptyGridCount()
    {
        return _stCardStorage.GetBagEmptyGridCount();
    }

public:
    unsigned int _uiGID;

private:
    int _iNowCardID;
    CUserStorage _stCardStorage;
    T_USER_CARD_HASH _stCardHash;
};


#endif // __CUserCard_h__

